package com.hrma.utils;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    private static final int OK = 200;
    private static final String OK_MSG = "成功";

    private static final int ERR = 501;
    private static final String ERR_MSG = "错误";

    public static final int MUST_HAS = 502;
    public static final int NOT_ALLOW_OPEN = 503;
    public static final int NOT_LOGIN = 900;
    public static final int NOT_POWER = 899;
    public static final int USER_OR_PASSWD = 898;
    public static final int PARA_VALID_ERROR = 897;

    public static final int NOT_ONE_DAY = 1111;
    private static final String NOT_ONE_DAY_MSG = "不是一天之内";
    public static final int IN_WORK_TIME= 1112;
    private static final String IN_WORK_TIME_MSG = "工作时间内不能申请加班";

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(OK, OK_MSG, data);
    }

    public static <T> Result<T> err(T data) {
        return err(ERR_MSG, data);
    }

    public static <T> Result<T> err(String errMessage, T data) {
        return new Result<>(ERR, errMessage, data);
    }

    public static <T> Result<T> err(int code, String errMessage, T data) {
        return new Result<>(code, errMessage, data);
    }


    public static <T> Result<T> notOneDay(T data) {
        return new Result<>(NOT_ONE_DAY, NOT_ONE_DAY_MSG, data);
    }

    public static <T> Result<T> inWorkTime(T data) {
        return new Result<>(IN_WORK_TIME, IN_WORK_TIME_MSG, data);
    }
}